package finalfinancialanalyst.business;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collection;
import java.util.Map;

public class Budget implements Serializable{
    
        private static final long serialVersionUID = 1L;
 
	private String category;
	 
	private Date startDate;
	 
	private Date endDate;
	 
	private BudgetType budgetType;
	 
	private Money money;
	 
	private Collection<Account> accounts;
	 
	public Budget() {
               accounts = new ArrayList<Account>();
	}
	 
	public boolean setCategory(String cat) {
                category = cat;
                return true;
                //TODO checks
	}
	 
	public String getCategory() {
		return category;
	}
	 
	public boolean delAccount(Account acc) {
            acc.unregisterBudget(this);
            return (accounts.remove(acc));
	}
	 
	public void setType(BudgetType type) {
                budgetType = type;
	}
	 
	public BudgetType getType() {
		return budgetType;
	}
	 
	public boolean addAccount(Account acc) {
            acc.registerBudget(this);
            return (accounts.add(acc));
	}
	 
	public void setStartDate(Date start) {
                startDate = start;
	}
	 
	public Date getStartDate() {
		return startDate;
	}
	 
	public void setEndDate(Date end) {
                endDate = end;
	}
	 
	public Date getEndDate() {
		return endDate;
	}
	 
	public void setAmount(Money amount) {
                money = amount;
	}
	 
	public Money getAmount() {
		return money;
	}
	 
	/**
	 * A method called by account telling this instance of budget that there was a new transaction on observed account
	 * 
	 * Part of Observer Design Pattern
	 */
	public void accountChangedNotification(Account acc) {
	 //TODO implement
	}
	 
	public Map getStats() {
		return null;
                //TODO implement
	}


        public String toCSVString(){
                StringBuilder buff = new StringBuilder();
                buff.append(category);
                buff.append(",");
                buff.append(startDate);
                buff.append(",");
                buff.append(endDate);
                buff.append(",");
                buff.append(budgetType);
                buff.append(",");
                buff.append(money);
                return buff.toString();
    }
}
 
